import React, { Component } from 'react'
import { ListView,View } from 'react-native'
import TextPost from './TextPost'

class TextPosts extends Component {

  constructor(props) {
    super(props);

    this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => {
      return r1 !== r2;
    }})

    // this.state = {
    //   dataSource: this.ds.cloneWithRows(props.datas)
    // }
  }

  // componentWillReceiveProps (nextProps) {
  //   if (nextProps.datas !== this.props.datas) {
  //     this.setState({
  //       dataSource: this.state.dataSource.cloneWithRows(nextProps.datas)
  //     })
  //   }
  // }

  renderRow(data) {

    return (
      <TextPost
        {...data}
        isFavorited={data.isFavorited}
        onFavoritePress={this.props.onFavoritePress}
        onLikePress={this.props.onLikePress}
      />
    )
  }

  render() {
    console.log('new TextPosts **************')
    const dataSource = this.ds.cloneWithRows(this.props.datas);
    return (
      <View style={{marginTop:50}}>
        <ListView
          dataSource={dataSource}
          renderRow={this.renderRow.bind(this)}
        />
      </View>
    )
  }
}

export default TextPosts
